import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
import 'package:mtf/R.dart';
import 'package:mtf/app/modules/authentication_module/authentication_controller.dart';
import 'package:mtf/app/theme/app_colors.dart';
import 'package:mtf/app/widget/AppBarLeftTitle.dart';
import 'package:permission_handler/permission_handler.dart';
/**
 * GetX Template Generator - fb.com/htngu.99
 * */

class authenticationPage extends GetView<authenticationController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBarLeftTitle(
        title: "实名认证",
        backgroundColor: c_f12f38,
      ),
      body: ListView.builder(
        shrinkWrap: true,
        itemBuilder: (context, index) {
          if (index == 0) {
            return Container(
              margin: EdgeInsets.all(10),
              width: double.infinity,
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(10), color: Colors.white),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    padding: EdgeInsets.symmetric(vertical: 5, horizontal: 10),
                    child: Row(
                      children: [
                        Text("姓名"),
                        Expanded(
                            flex: 1,
                            child: TextField(
                              textAlign: TextAlign.right,
                              decoration: InputDecoration(
                                hintText: "请填写姓名",
                                hintStyle:
                                TextStyle(fontSize: 14, color: c_999999),
                                border: InputBorder.none,
                              ),
                              style: TextStyle(color: c_333333, fontSize: 14),
                              controller: controller.nameController,
                            ))
                      ],
                    ),
                  ),
                  Divider(
                    height: 1,
                  ),
                  Container(
                    padding: EdgeInsets.symmetric(vertical: 5, horizontal: 10),
                    child: Row(
                      children: [
                        Text("身份证号"),
                        Expanded(
                            flex: 1,
                            child: TextField(
                              textAlign: TextAlign.right,
                              decoration: InputDecoration(
                                hintText: "请填写身份证号",
                                hintStyle:
                                TextStyle(fontSize: 14, color: c_999999),
                                border: InputBorder.none,
                              ),
                              style: TextStyle(color: c_333333, fontSize: 14),
                              controller: controller.cardController,
                            ))
                      ],
                    ),
                  ),
                  Divider(
                    height: 1,
                  ),
                  Container(
                    padding: EdgeInsets.symmetric(vertical: 5, horizontal: 10),
                    child: Row(
                      children: [
                        Text("开户行名称"),
                        Expanded(
                            flex: 1,
                            child: TextField(
                              textAlign: TextAlign.right,
                              decoration: InputDecoration(
                                hintText: "请填写开户行名称",
                                hintStyle:
                                TextStyle(fontSize: 14, color: c_999999),
                                border: InputBorder.none,
                              ),
                              style: TextStyle(color: c_333333, fontSize: 14),
                              controller: controller.bankNameController,
                            ))
                      ],
                    ),
                  ),
                  Divider(
                    height: 1,
                  ),
                  Container(
                    padding: EdgeInsets.symmetric(vertical: 5, horizontal: 10),
                    child: Row(
                      children: [
                        Text("银行卡号"),
                        Expanded(
                            flex: 1,
                            child: TextField(
                              textAlign: TextAlign.right,
                              decoration: InputDecoration(
                                hintText: "请填写银行卡号",
                                hintStyle:
                                TextStyle(fontSize: 14, color: c_999999),
                                border: InputBorder.none,
                              ),
                              style: TextStyle(color: c_333333, fontSize: 14),
                              controller: controller.bankNumController,
                            ))
                      ],
                    ),
                  ),
                  Divider(
                    height: 1,
                  ),
                  Container(
                    alignment: Alignment.center,
                    padding: const EdgeInsets.symmetric(vertical: 15),
                    child: Text("上传身份证正反面"),
                  ),
                    Row(
                      children: [
                        Expanded(
                          flex: 1,
                          child: InkWell(
                            onTap: () {
                              photoDialog(0);
                            },
                            child: Obx(() {
                              return Column(
                                children: [
                                  controller.idCardUp.value.isEmpty ?
                                  Image.asset(
                                    R.assetsImgBgIdCardUp,
                                    width: double.infinity,
                                    height: 120,
                                  ) :
                                  Image.network(
                                    controller.idCardUp.value,
                                    width: double.infinity,
                                    height: 120,
                                  ),
                                  Padding(
                                    padding:
                                    const EdgeInsets.symmetric(vertical: 10),
                                    child: Text("身份证人像面"),
                                  )
                                ],
                              );
                            }),
                          ),
                        ),
                        Expanded(
                          flex: 1,
                          child: InkWell(
                            onTap: () {
                              photoDialog(1);
                            },
                            child: Obx(() {
                              return Column(
                                children: [
                                  controller.idCardBack.value.isEmpty ?
                                  Image.asset(
                                    R.assetsImgBgIdCardDown,
                                    width: double.infinity,
                                    height: 120,
                                  ) :
                                  Image.network(
                                    controller.idCardBack.value,
                                    width: double.infinity,
                                    height: 120,
                                  ),
                                  Padding(
                                    padding:
                                    const EdgeInsets.symmetric(vertical: 10),
                                    child: Text("身份证国徽面"),
                                  )
                                ],
                              );
                            }),
                          ),
                        )
                      ],
                    ),
                  Container(
                    alignment: Alignment.center,
                    padding: const EdgeInsets.symmetric(vertical: 15),
                    child: Text("上传银行卡正面照片"),
                  ),
                  Row(
                    children: [
                      Expanded(
                        flex: 1,
                        child: InkWell(
                          onTap: () {
                            photoDialog(2);
                          },
                          child: Obx(() {
                            return Column(
                              children: [
                                controller.bankFontBack.value.isEmpty ?
                                Image.asset(
                                  R.assetsImgBgBankFont,
                                  width: double.infinity,
                                  height: 120,
                                ) :
                                Image.network(
                                  controller.bankFontBack.value,
                                  width: double.infinity,
                                  height: 120,
                                ),
                                Padding(
                                  padding:
                                  const EdgeInsets.symmetric(vertical: 10),
                                  child: Text("银行卡正面照"),
                                )
                              ],
                            );
                          }),
                        ),
                      ),
                      Expanded(
                        flex: 1,
                        child: Container(),
                      )
                    ],
                  ),
                ],
              ),
            );
          } else {
            return Container(
              margin: const EdgeInsets.only(top: 40, left: 10, right: 10),
              width: double.maxFinite,
              height: 48,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(24),
                color: c_f12f38,
              ),
              child: TextButton(
                  child: Text("提交", style: TextStyle(color: Colors.white,
                      fontSize: 16,
                      fontWeight: FontWeight.bold)),
                  onPressed: () {
                    controller.reqAuth();
                  }
              ),
            );
          }
        },
        itemCount: 2,
      ),
    );
  }

  void photoDialog(int tag) {
    showGeneralDialog<String>(
        context: Get.context!!,
        barrierLabel: '',
        barrierDismissible: false,
        barrierColor: Colors.black.withOpacity(0.2),
        pageBuilder: (context, animation, secondaryAnimation) {
          return Align(
            alignment: Alignment.bottomCenter,
            child: Container(
              height: 171,
              color: Colors.transparent,
              margin: EdgeInsets.only(left: 15, right: 15), //控制底部的距离
              child: Column(
                children: <Widget>[
                  Container(
                    height: 101,
                    decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(10.0),
                    ),
                    child: Column(
                      children: <Widget>[
                        InkWell(
                          onTap: () {
                            controller.selectCamera(tag);
                          },
                          child: Container(
                            height: 50,
                            child: Center(
                              child: Text(
                                '拍照',
                                style: TextStyle(
                                    color: c_333333,
                                    letterSpacing: 2.0,
                                    fontWeight: FontWeight.w200),
                              ),
                            ),
                          ),
                        ),
                        Divider(height: 1),
                        InkWell(
                          onTap: () {
                            controller.selectImage(tag);
                          },
                          child: Container(
                            height: 50,
                            child: Center(
                              child: Text(
                                '本地相册',
                                style: TextStyle(
                                    color: c_333333,
                                    letterSpacing: 2.0,
                                    fontWeight: FontWeight.w200),
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                  InkWell(
                    onTap: () {
                      Get.back();
                    },
                    child: Container(
                      margin: EdgeInsets.only(
                        top: 10,
                        bottom: 10,
                      ),
                      height: 50,
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(10.0),
                      ),
                      child: Center(
                        child: Text(
                          '取消',
                          style: TextStyle(
                              color: c_808080,
//                          fontSize: Config.fontSize17,
                              fontWeight: FontWeight.w200),
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          );
        });
  }


}
